<?php
/*************************************************************************
Class Pick_Dao_RequestAdCategory
----------------------------------------------------------------
PICKCO CMS Project
Company: PICKCO  Co., Ltd  
Email: admin@pick.vn
Last updated: 15/07/2008
**************************************************************************/
class Pick_Dao_RequestAdCategory extends Pick_Dao_Objects {
	function Pick_Dao_RequestAdCategory($database = '') {
		if(!$database) {
			global $db;
			$this->_db = $db;
		} else $this->_db = $database;
		$this->typeId = " AND typeid = 15";
		$this->objectInfo = "Pick_Dao_RequestAdCategoryInfo";
		$this->table = DB_PREFIX."category";	
	}
/*-----------------------------------------------------------------------*
* Function: cleanTrash
* Parameter: WHERE catproduct
* Return:array ID
*-----------------------------------------------------------------------*/	
	function cleanTrash($condition = '1=1'){
		$dem = 0;
		$objectDelete = $this->getObjects(1, $condition . ' AND status = 2', '', '');
		foreach($objectDelete as $object){
			$arrayIdCategory = $this->getIdSubCategory($object->getField('id'),1);
			$news = new News;
			$arrayObject = $news->getObjectsFromArrayCId(1,$arrayIdCategory);
			foreach($arrayObject as $objectImages){
				$ok1 = $objectImages->deleteAvatar();
				$ok2 = $news->delete("id = " . $objectImages->getField('id'));
				if(!$ok1 && !$ok2) $dem++;				
			}
			$dem = $this->delete('id IN(' . implode(",", $arrayIdCategory).')  AND status = 2')?$dem:$dem+1;
		}
		return $dem==0?true:false;
	}	
}
?>